<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<form:form id="deleteCategory" method="POST">
    <input type="hidden" id="deleteCategoryId" name="categoryId"/>
</form:form>

<form:form method="post" commandName="category" id="formModify">
    <div id="div_categories">
        <h4>Categories list:</h4>
        <table class="category_table">
            <tr>
                <th></th>
                <th>Name</th>
                <th colspan="2">Action</th>
            </tr>
            <c:forEach items="${categoryList}" var="category">
                <tr id="${category.id}">
                    <td><input type="hidden" class="hiddenCategId" name="category_id" value="${category.id}"/></td>
                    <td><input class="_no_border" type="text" name="category_name" value="${category.name}"/></td>
                    <td><a href="#" onclick="disableOtherRows('${category.id}');">Edit</a></td>
                    <td><a href="#" onclick="deleteCategory('${category.id}')">Delete</a></td>
                </tr>
            </c:forEach>
        </table>
    </div>
    <c:set var="message" value="${param['successMessage']}"/>
    <c:if test="${message != null}">
        <span><fmt:message key="${message}"/></span>
    </c:if>
    <c:set var="message" value="${param['errorMessage']}"/>
    <c:if test="${message != null}">
        <span class="error"><fmt:message key="${message}"/></span>
    </c:if>
</form:form>

<form:form id="addCatForm" method="post" commandName="category">
    <br/>

    <div id="new_category">
        <h4>Add new category</h4>
    </div>
    <table id="div_add_cat">
        <tr>
            <td>Category name:</td>
        </tr>
        <tr>
            <td><form:input path="name"/><form:errors path="name" class="error"/></td>
        </tr>
        <tr>
            <td id="add_cat"><input class="no_border" id="add_category" onclick="addCategory()" type="button"
                                    value="Add category"/></td>
        </tr>
    </table>
</form:form>